//获取应用实例
const app = getApp()
Page({
	data:{
		cardTicket:{},
		page:1,
		isData:true
	},
	onPullDownRefresh:function(){
		var that = this;
		//我的订单
		app.request('/api/Coupon/myExchangeList', {page:1}, function(res){
			if(res.code == '0'){
				//更新数据
				that.setData({
					cardTicket:res.data.data
				});
			}
		});
	},
	onReachBottom:function(){
		var that = this;
		that.data.page++;
		//我的订单
		app.request('/api/Coupon/myExchangeList', {page:that.data.page}, function(res){
			if(res.code == '0'){
				//更新数据
				that.setData({
					cardTicket:that.data.cardTicket.push[res.data.data]
				});
			}
		});
	},
	onLoad:function(){
		var that = this;
		//我的订单
		app.request('/api/Coupon/myExchangeList', {page:1}, function(res){
			if(res.code == '0'){
				that.setData({
					cardTicket:res.data.data,
					isData:false
				});
				if(res.data.data.length == 0){
					that.setData({
						isData:false
					})
				} 
				else{
					that.setData({
						isData:true
					})
					for(var i=that.data.cardTicket.length-1; i>=0; i--){
						if(that.data.cardTicket[i].type == 4){
						    if(that.data.cardTicket[i].title.indexOf('门票') > 0){
								that.data.cardTicket[i].type = 5
							}
						}
					}
					that.setData({
						cardTicket:that.data.cardTicket
					})
				}
			}
		});
	}
})